<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>添加下级代理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <%-- <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/theme/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/theme/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/theme/style.css" /> --%>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/theme/jquery.js"></script>
    <%-- <script type="text/javascript" src="${pageContext.request.contextPath}/js/theme/bootstrap.js"></script> --%>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/theme/ckform.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/theme/common.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/layerui/layer.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/layerui/layer.ext.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/common/checkFormat.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/skin/css/mobilecss/charge.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/skin/css/mobilecss/main.css">

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
		.container span {
			display: inline-block;
			 border:none;
			 padding: 0.5rem;
			 width:20%;
			 text-align: right;
		}

    </style>
</head>
<body>

<div class="container">
        <p style="font-size: 0.9rem" id="addTitle">添加下级推广员</p>
        <div style="border: 1px solid #636363;font-size: 0.9rem;width: 100%">
            <span >游戏id</span>
            <input type="text" id="uid" placeholder="填写此代理在app中的Id" name="uid" style="border: none;width: 60%;background-color: #FFFFFF">
            <!-- <button id="queryPlayer">绑定玩家</button> -->
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">姓名</span>
            <input type="text" id="realname" name="realname" placeholder="填写代理商的真实姓名" style="border: none;width: 60%;background-color: #FFFFFF">
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">手机号</span>
            <input type="tel" id="uphone" name="uphone" placeholder="将作为该用户后台系统的登录账号名" onkeyup="value=value.replace(/[^\d]/g,'')" maxLength="11" style="border: none;width: 60%">
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">密码</span>
            <input type="password" id="pwd" name="pwd" placeholder="将作为该用户后台系统的登录密码" style="border: none;width: 60%;background-color: #FFFFFF">
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">确认密码</span>
            <input type="password" id="pwd1" name="pwd1" placeholder="将作为该用户后台系统的登录密码" style="border: none;width: 60%;background-color: #FFFFFF">
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">微信号</span>
            <input type="text" id="wechat" name="wechat" placeholder="填写代理的微信号" style="border: none;width: 60%;background-color: #FFFFFF">
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">推广员级别</span>
            <!-- style="width: 71%;display: inline-block;border: 1px solid #636363;padding: 0.5rem;color: #999"  style="height:34px;width:100%;" -->
             <select id="userLevel" placeholder="填写代理的微信号" style="border: none;width: 60%;background-color: #FFFFFF">
                <c:forEach items="${profitRule}" var="profitRule">
                	<option value="${profitRule.id}">${profitRule.name}</option>
                </c:forEach> 
             </select>
        </div>
        <div style="border: 1px solid #636363">
            <span style="border:none;padding: 0.5rem;">邀请码</span>
            <input type="text" id="code" name="code" onkeyup="value=value.replace(/[^\d]/g,'')"  maxLength="5" placeholder="请填写邀请码~" style="border: none;width: 60%;background-color: #FFFFFF">
        </div>
       
        <div style="margin-top: 3rem">
            <button style="width: 100%" onClick="addAgentCheck()">确认添加</button>
        </div>
    </div>
    <div class="alert" id="myalert" style="display: none">
        <div>
        	<p>该玩家昵称： <span style="color: red" id="playerId"></span> &nbsp;&nbsp; 请确保无误。</p>
        	<p>玩家ID：<span id="uidspan"></span></p>
            <p>姓名：<span id="realNamespan"></span></p>
            <p>手机号:<span id="mobilespan"></span></p>
            <div style="position: relative">
                <button id="usersave" >确认添加</button>
                <button style="position: absolute;top: 0;right: 0;background-color: #666"  onClick="addAgentCancel()" >取消</button>
            </div>
        </div>
    </div>
    <div class="alert" id="sysalert" style="display: none">
	    <div>
	        <u style="position: absolute;top: 5%;right: 2%;padding: 0.5rem" class="close"></u>
	        <p style="margin: 1rem 0" id="sysmsg"></p>
	    </div>
	</div>
</body>
<script>
    $(function () {       
		$('#backid').click(function(){
			var system ={}; 
	        var p = navigator.platform;      
	        system.win = p.indexOf("Win") == 0; 
	        system.mac = p.indexOf("Mac") == 0; 
	        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);    
	        if(system.win||system.mac||system.xll){
	    		//如果是电脑跳转到弹出框 
	        	parent.layer.close(parent.lindex);
	        }else{  
	    		//如果是手机,跳转到页签
	    		window.location.href="${pageContext.request.contextPath}/admin/user_next_info.html";
	        }
		 });
		
		$('#usersave').click(function(){
			$('#usersave').attr('disabled',"true"); //添加disabled属性 
			var realname = $("#realname").val();
			var uphone = $("#uphone").val();
			var wechat = $("#wechat").val();
			var uid = $("#uid").val();
			var pwd = $("#pwd").val();
			var pwd1 = $("#pwd1").val();
			var code= $("#code").val(); // 邀请码
			var userLevel= $("#userLevel").val();
			if(realname==""){
				layer.alert("请填写用户名~");
				return;
			}
			if(uphone==""){
				layer.alert("请填写手机~");
				return;
			}
			if(code==""){
				layer.alert("请填写邀请码~");
				return;
			}
			
			$.post("${pageContext.request.contextPath}/admin/user_save.html",
		            {"realname":realname,"uphone":uphone,"wechat":wechat
				,"uid":uid,"pwd":pwd,"userLevel":userLevel,"code":code},
		       function(data){
		            	var json = eval("("+data+")");
		            	$('#usersave').removeAttr("disabled");  //移除disabled属性 
						layer.alert(json.message);
						if(json.statusCode =='200'){
							setTimeout("closeAgentCancel()",2000);
						}
		      });
		 });
    });
  
    function addAgentCancel() {
	    $("#myalert").css("display","none");
    }
    
    function closeAgentCancel() {
    	 $("#myalert").css("display","none");
	    window.location.href="${pageContext.request.contextPath}/admin/user_next_info_mobile.html";
    }
    
    function addAgentCheck() {
    	var realname = $("#realname").val();
		var uphone = $("#uphone").val();
		var wechat = $("#wechat").val();
    	var uid = $("#uid").val();
    	var code= $("#code").val(); // 邀请码
    	var pwd = $("#pwd").val();
		var pwd1 = $("#pwd1").val();
    	if(pwd!=pwd1){
    		layer.alert('两次输入的密码不一致~');
    		return;
    	}
    	//校验
    	if(uphone=="") {
    		layer.alert('手机号不能为空~');
    		return;
    	} else if(uphone.length != 11) {
    		layer.alert( '手机号位数不对~');
    		return;
    	}else if(realname=="") {
    		layer.alert('姓名不能为空~');
    		return;
    	} else if(checkSpecial(realname)) {
    		layer.alert( '姓名和描述不能包含特殊字符~');
    		return;
    	} else if((checkChina(realname) && realname.length > 8) || (!checkChina(realname) && realname.length > 16)) {
    		layer.alert( '姓名不能超过8个汉字或16个字母~');
    		return;
    	} 
		$.post("${pageContext.request.contextPath}/admin/query_user.html",
	            {"uid":uid,"code":code},
	       function(data){
            	var json = eval("("+data+")");
				if(json.statusCode =='200'){
					$("#playerId").html(json.playerName);
			    	$("#mobilespan").html(uphone);
			    	$("#realNamespan").html(realname);
			    	$("#uidspan").html(uid);
			    	$("#myalert").css("display","block");
				}else{
					layer.alert(json.message);
				}
	     });
    }
    
</script>
</html>